package com.yxpweb.redisdao.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.Objects;

/**
 * 视频信息
 *
 * @author YH.L
 * @date 2020年11月19日.
 **/
@Document(collection = "video_info")
@CompoundIndexes({@CompoundIndex(name = "PlayerId_Id_Idx", def = "{'playerId': 1, '_id': -1}")})
public class VideoInfo {
    @Id
    private long id;
    private String title;
    private String url;
    private Date createDate;
    @Indexed
    private long playerId;
    private volatile int commentCount;
    @Indexed
    private volatile int likeCount;
    private boolean first = false; // 首页推荐
    private int playbackTimes;

    public VideoInfo() {
    }

    public VideoInfo(long id, long playerId, String title, String url) {
        this.id = id;
        this.playerId = playerId;
        this.title = title;
        this.url = url;
        this.createDate = new Date();
        this.commentCount = 0;
        this.likeCount = 0;
        this.playbackTimes = 0;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public long getPlayerId() {
        return playerId;
    }

    public void setPlayerId(long playerId) {
        this.playerId = playerId;
    }

    public int getCommentCount() {
        return commentCount;
    }

    public void setCommentCount(int commentCount) {
        if (commentCount < 0) {
            commentCount = 0;
        }
        this.commentCount = commentCount;
    }

    public int getLikeCount() {
        return likeCount;
    }

    public void setLikeCount(int likeCount) {
        if (likeCount < 0) {
            likeCount = 0;
        }
        this.likeCount = likeCount;
    }

    public int getPlaybackTimes() {
        return playbackTimes;
    }

    public void setPlaybackTimes(int playbackTimes) {
        this.playbackTimes = playbackTimes;
    }

    public boolean isFirst() {
        return first;
    }

    public void setFirst(boolean first) {
        this.first = first;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        VideoInfo videoInfo = (VideoInfo) o;
        return id == videoInfo.id;
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
